#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      Student
#
# Created:     17/07/2012
# Copyright:   (c) Student 2012
# Licence:     <your licence>
#-------------------------------------------------------------------------------

import random

class card:
    suits=["Hearts","Clubs","Diamonds","Spades"]
    values=[]
    cardList=[]
    deck=[]
    player1=[]
    player2=[]
    p1num=26
    p2num=26
    p1war=[]
    p2war=[]
    p1current=[]
    p2current=[]
    def createValues(asdf):
        for x in range(2,11):
            card.values.append(str(x))
        card.values.append("Jack")
        card.values.append("Queen")
        card.values.append("King")
        card.values.append("Ace")
    def createCards(asdf):
        for x in card.suits:
            for y in card.values:
                card.cardList=[x, y]
                card.deck.append(card.cardList)
    def splitDeck(asdf):
        random.seed()
        random.shuffle(card.deck)
        for x in range(0,26):
            card.player1.append(card.deck[x])
            card.player2.append(card.deck[x+26])
    def play(asdf):
        while(card.p1num>0 and card.p2num>0):
            card.p1current=card.player1.pop(0)
            card.p2current=card.player2.pop(0)
            print(card.p1current, end=" ")
            print("vs ")
            print(card.p2current)
            card.p1value=card.assignVal(str(card.p1current[1]))
            card.p2value=card.assignVal(str(card.p2current[1]))
            if(card.p1value>card.p2value):
                card.player1.append(card.p1current)
                card.player1.append(card.p2current)
                card.p1num+=1
                card.p2num-=1
                print(card.p1current, end=" ")
                print("wins")
            elif(card.p1value>card.p2value):
                card.player2.append(card.p1current)
                card.p1ayer2.append(card.p2current)
                card.p2num+=1
                card.p1num-=1
                print(card.p2current, end=" ")
                print("wins")
            else:
                card.war()

    def war():
        card.p1war.append(card.p1current)
        card.p1war.append(card.player1.pop(0))
        card.p1war.append(card.player1.pop(0))
        card.p1war.append(card.player1.pop(0))
        card.p2war.append(card.p2current)
        card.p2war.append(card.player2.pop(0))
        card.p2war.append(card.player2.pop(0))
        card.p2war.append(card.player2.pop(0 ))
        if(card.assignVal(card.p1war[len(card.p1war)-1])>card.assignVal(card.p2war[len(card.p2war)-1])):
            card.p1num+=len(card.p2war)
            card.p1num-=len(card.p1war)
            for x in range(0,len(card.p1war)):
                card.player1.append(card.p1war.pop())
                card.player1.append(card.p2war.pop())
        elif(card.assignVal(card.p2war[len(card.p2war)-1])>card.assignVal(card.p1war[len(card.p1war)-1])):
            card.p1num-=len(card.p2war)
            card.p1num+=len(card.p1war)
            for x in range(0,len(card.p2war)):
                card.player2.append(card.p1war.pop())
                card.player2.append(card.p2war.pop())
        else:
            card.war()


    def assignVal(curr):
        if(curr=="Jack"):
            return 11
        elif(curr=="Queen"):
            return 12
        elif(curr=="King"):
            return 13
        elif(curr=="Ace"):
            return 14
        else:
            return (int)(curr)



def main():
    card1 = card()
    card1.createValues()
    card1.createCards()
    card1.splitDeck()
    card1.play()
    pass

if __name__ == '__main__':
    main()
